#ifndef WINDOWMANAGER_H
#define WINDOWMANAGER_H

#include <QObject>
#include <QHash>
#include <functional>
#include "qluiutility.h"
#include "qlui_global.h"

class Window;

class QLUISHARED_EXPORT WindowManager : public QObject
{
    Q_OBJECT
public:
    explicit WindowManager(QObject *parent = 0);
    virtual ~WindowManager();

    bool addWindow(Window *w);
    Window *activeWindow() const;
    quint32 invalidID() const;
    quint32 nextID();

    typedef std::function<void(int, int)> Handle;
    void setDefaultHandle(const Handle &h);

private:
    QHash<quint32, Window*> windows_;
    quint32 last_auto_id_;
    Handle default_handle_;


    /*********************************************************************
     *                    Event
     * *******************************************************************/
public slots:
    bool switchWindowTo(quint32 id);
    void onKeyboardEvent(int key, int value);

protected slots:
    void onWindowVisiableChanged(bool visiable);

signals:
    void keyEvent(int key, int value);
    void moveEvent(MoveDirection direction);

private:
    Window *active_window_;
};

#endif // WINDOWMANAGER_H
